﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XML的序列化与反序列化;
using XML的序列化与反序列化.common;

namespace publish_test.XMLSerializer
{
    public class XMLSerializerHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            bool isSerializer = false;
            bool.TryParse(context.Request["Serializer"],out isSerializer);
            if (isSerializer)
            {
                userInfo us = new userInfo() {
                    Invisisible = "true",
                    Ip = "www.baidu.com",
                    NickName = Guid.NewGuid().ToString().Substring(0, 5),
                     Password=new Random().Next(100000,999999).ToString(),
                      UserId=new Random().Next(999999),
                       UserName= Guid.NewGuid().ToString().Substring(0, 5)
                };
                XmlSerializerUnitity<userInfo>.XMLSerialize(us, context.Server.MapPath("xml测试.xml"));
            }
            else
            {
             var us=   XmlSerializerUnitity<userInfo>.XMLDeserialize(context.Server.MapPath("xml测试.xml"));

                context.Response.Write("Invisisible"+ us.Invisisible+ ";Ip:" + us.Ip + ";NickName:" + us.NickName + ";Password:" + us.Password + ";UserId:" + us.UserId + ";UserName:" + us.UserName );
            }
        }
    }
}